//
//  FSDressDetailViewController.m
//  Trade
//
//  Created by 刘沿 on 16/4/14.
//  Copyright © 2016年 刘沿. All rights reserved.
//

#import "FSDressDetailViewController.h"

@interface FSDressDetailViewController ()
@property(nonatomic,strong)NSDictionary *dict;

//@property (weak, nonatomic) IBOutlet UILabel *first;
//
@property (weak, nonatomic) IBOutlet UILabel *nameLabel;

@property (weak, nonatomic) IBOutlet UILabel *desLabel;

@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;

@property (weak, nonatomic) IBOutlet UILabel *shortLabel;

@property (weak, nonatomic) IBOutlet UILabel *telPhoneLabel;

@property (weak, nonatomic) IBOutlet UILabel *typeLabel;

//电话栏
- (IBAction)callPhoneAction:(UIButton *)sender;

- (IBAction)sendSMSAction:(UIButton *)sender;

//短号
- (IBAction)duanhao:(id)sender;

- (IBAction)duanhaoMES:(id)sender;

@property (weak, nonatomic) IBOutlet UIButton *duanhaoPhone;

@property (weak, nonatomic) IBOutlet UIButton *duanhaoMES;

//13位号
@property (weak, nonatomic) IBOutlet UIButton *CHPhone;

@property (weak, nonatomic) IBOutlet UIButton *CHTelPhone;



@property (weak, nonatomic) IBOutlet UIButton *zuojiTel;

@end

@implementation FSDressDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self requestData];

}

//-(UIColor *) randomColor
//{
//    CGFloat hue = ( arc4random() % 256 / 256.0 ); //0.0 to 1.0
//    CGFloat saturation = ( arc4random() % 128 / 256.0 ) + 0.5; // 0.5 to 1.0,away from white
//    CGFloat brightness = ( arc4random() % 128 / 256.0 ) + 0.5; //0.5 to 1.0,away from black
//    return [UIColor colorWithHue:hue saturation:saturation brightness:brightness alpha:1];
//    
//}

-(void)requestData{
    [MBProgressHUD showHUDAddedTo:self.navigationController.view animated:YES];
    NSString * userId = [[NSUserDefaults standardUserDefaults]objectForKey:@"userId"];
    NSArray *  array = @[@{@"path":self.unid},@{@"userId":userId}];;
    [HttpTools requestWithURL:KExchother arrays:array method:KContentTxlMethod success:^(id JSON) {
        [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];

        NSArray * tempArray = JSON[@"data"];
        NSDictionary *dict = [tempArray firstObject];
        
        NSLog(@"%@",dict);
        
        [self setupSubViews:dict];
        
        
    } failure:^(NSError *error) {
        [MBProgressHUD hideAllHUDsForView:self.navigationController.view animated:YES];
    }];
    
}

-(void)setupSubViews:(NSDictionary*)dict{
    
//    self.first.text = dict[@"surname"];
    self.nameLabel.text = dict[@"name"];
    self.desLabel.text = [NSString stringWithFormat:@"%@",dict[@"duties"]];
    self.phoneLabel.text = dict[@"telphone"];
    self.telPhoneLabel.text = dict[@"officephone"];
    self.typeLabel.text = dict[@"unit"];
    self.shortLabel.text = dict[@"cornet"];
    self.dict = dict;
    
    if (self.telPhoneLabel.text.length == 0) {
        
        self.zuojiTel.hidden = YES;
    }
    
    if (self.shortLabel.text.length == 0) {
        self.duanhaoPhone.hidden = YES;
        self.duanhaoMES.hidden = YES;
        
    }
    
    if (self.telPhoneLabel.text.length == 0) {
        self.zuojiTel.hidden = YES;
    }
    
    if (self.phoneLabel.text.length == 0) {
        self.CHPhone.hidden = YES;
        self.CHTelPhone.hidden = YES;
        
    }
    
    
}

- (IBAction)callPhoneAction:(UIButton *)sender {
    NSString * phone = [NSString stringWithFormat:@"tel://%@",self.dict[@"telphone"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phone]];//打电话
    
}

- (IBAction)sendSMSAction:(UIButton *)sender {
    NSString * phone = [NSString stringWithFormat:@"sms://%@",self.dict[@"telphone"]];
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:phone]];//发短信
    
}

//短号
- (IBAction)duanhao:(id)sender {
    
    NSString * phone = [NSString stringWithFormat:@"tel://%@",self.dict[@"cornet"]];
    [[UIApplication sharedApplication] openURL:[NSURL URLWithString:phone]];//打电话
}

- (IBAction)duanhaoMES:(id)sender {
    
    NSString * phone = [NSString stringWithFormat:@"sms://%@",self.dict[@"cornet"]];
    [[UIApplication sharedApplication]openURL:[NSURL URLWithString:phone]];//发短信
    

}
@end
